/**
 * Created by Administrator on 2016-10-13.
 */
function orderSearchClick(url,request) {

    var begintime = $.trim($("#datetimepicker_searchbegin").val());
    var endtime = $.trim($("#datetimepicker_searchend").val());
    var keyword = $.trim($("#search_keyvalue").val());

    if ((begintime == "") && (endtime == "") && (keyword == "")) {
        var data = null;
    } else {
        if ((begintime != "") && (endtime != "") && (keyword != "")) {
            var data = {
                "beginTime": begintime + " 00:00:00",
                "endTime": endtime + " 23:59:59",
                "keyWord": keyword
            }
        } else if ((begintime == "") && (endtime == "") && (keyword != "")) {
            var data = {
                "keyWord": keyword
            }
        } else if ((begintime == "") && (endtime != "") && (keyword != "")) {
            var data = {
                "keyWord": keyword
            }
        } else if ((begintime != "") && (endtime == "") && (keyword != "")) {
            var data = {
                "keyWord": keyword
            }
        } else if ((begintime != "") && (endtime != "") && (keyword == "")) {
            var data = {
                "beginTime": begintime + " 00:00:00",
                "endTime": endtime + " 23:59:59"
            }
        } else {
            var data = null;
        }
    }
    if (data == null) {
        alert("请输入时间或者关键字进行查询");
    } else {
        $.ajax({
            url: url,
            type: request,
            data: data,
            dataType: 'json',

            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    //console.log(data);
                    //使用baidu.template命名空间
                    var bt = baidu.template;
                    //最简使用方法
                    var html = bt('carList', data);
                    total = data.data.total;
                    //template.config("escape", false);

                    //渲染
                    $("#result").html(html);


                    $("#totalpage").html(total);
                    $('#pageTool').empty();
                    $('#pageTool').Paging({
                        pagesize: 10, count: total, callback: function (page, size, count) {

                            // alert('当前第 ' +page +'页,每页 '+size+'条,总页数：'+count+'页');
                            var url = "apis/order/orderViewList";
                            var begintime = $.trim($("#datetimepicker_searchbegin").val());
                            var endtime = $.trim($("#datetimepicker_searchend").val());
                            var keyword = $.trim($("#search_keyvalue").val());

                            if ((begintime == "") && (endtime == "") && (keyword == "")) {
                                var data = {
                                    "pageNum": page
                                }
                            } else {
                                if ((begintime != "") && (endtime != "") && (keyword != "")) {
                                    var data = {
                                        "beginTime": begintime + " 00:00:00",
                                        "endTime": endtime + " 23:59:59",
                                        "keyWord": keyword,
                                        "pageNum": page
                                    }
                                } else if ((begintime == "") && (endtime == "") && (keyword != "")) {
                                    var data = {
                                        "keyWord": keyword,
                                        "pageNum": page
                                    }
                                } else if ((begintime == "") && (endtime != "") && (keyword != "")) {
                                    var data = {
                                        "keyWord": keyword,
                                        "pageNum": page
                                    }
                                } else if ((begintime != "") && (endtime == "") && (keyword != "")) {
                                    var data = {
                                        "keyWord": keyword,
                                        "pageNum": page
                                    }
                                } else if ((begintime != "") && (endtime != "") && (keyword == "")) {
                                    var data = {
                                        "beginTime": begintime + " 00:00:00",
                                        "endTime": endtime + " 23:59:59",
                                        "pageNum": page
                                    }
                                } else {
                                    var data = {
                                        "pageNum": page
                                    }
                                }
                            }

                            if (data == null) {
                                alert("请输入时间或者关键字进行查询");
                            } else {
                                $.ajax({
                                    url: url,
                                    type: request,
                                    data: data,
                                    dataType: 'json',

                                    success: function (data, status, xhr) {
                                        if (data.httpCode == 200) {
                                            //使用baidu.template命名空间
                                            var bt = baidu.template;
                                            //最简使用方法
                                            var html = bt('carList', data);
                                            //template.config("escape", false);

                                            //渲染
                                            $("#result").html(html);
                                        } else {
                                            alert(data.data);
                                        }

                                    }

                                })
                            }
                        }
                    });
                } else {
                    alert(data.data);
                }

            }

        })
    }
    //分页开始，分页结束
}


function orderListInit(url) {
    $.post(url,function(res) {
        //console.log(res);
        /*optional stuff to do after success */

        var data = res
        total = res.data.total;

        //使用baidu.template命名空间
        var bt=baidu.template;


        //最简使用方法
        var html=bt('carList',data);
        //template.config("escape", false);

        //渲染
        $("#result").html(html);
        $("#totalpage").html(total);
        $('#pageTool').empty();
        $('#pageTool').Paging({pagesize:10,count:total,callback:function(page,size,count){

            // alert('当前第 ' +page +'页,每页 '+size+'条,总页数：'+count+'页');
            var begintime = $.trim($("#datetimepicker_searchbegin").val());
            var endtime = $.trim($("#datetimepicker_searchend").val());
            var keyword = $.trim($("#search_keyvalue").val());

            if ((begintime == "") && (endtime == "") && (keyword == "")) {
                var data = {
                    "pageNum":page
                }
            } else {
                if ((begintime != "") && (endtime != "") && (keyword != "")) {
                    var data = {
                        "beginTime": begintime + " 00:00:00",
                        "endTime": endtime + " 23:59:59",
                        "keyWord": keyword,
                        "pageNum":page
                    }
                } else if ((begintime == "") && (endtime == "") && (keyword != "")) {
                    var data = {
                        "keyWord": keyword,
                        "pageNum":page
                    }
                } else if ((begintime == "") && (endtime != "") && (keyword != "")) {
                    var data = {
                        "keyWord": keyword,
                        "pageNum":page
                    }
                } else if ((begintime != "") && (endtime == "") && (keyword != "")) {
                    var data = {
                        "keyWord": keyword,
                        "pageNum":page
                    }
                } else if ((begintime != "") && (endtime != "") && (keyword == "")) {
                    var data = {
                        "beginTime": begintime + " 00:00:00",
                        "endTime": endtime + " 23:59:59",
                        "pageNum":page
                    }
                } else {
                    var data = {
                        "pageNum":page
                    }
                }
            }


            if (data == null) {
                alert("请输入时间或者关键字进行查询");
            } else {
                $.ajax({
                    url: url,
                    type: 'post',
                    data: data,
                    dataType: 'json',
                    success: function (data, status, xhr) {
                        // console.log(data)
                        if (data.httpCode == 200) {
                            //使用baidu.template命名空间
                            var bt = baidu.template;
                            //最简使用方法
                            var html = bt('carList', data);
                            //template.config("escape", false);

                            //渲染
                            $("#result").html(html);
                        } else {
                            alert(data.data);
                        }

                    }

                })
            }
        }});

    });
}

